package comp302.prototype.misc;

import java.awt.Point;

public class MiscMath {

	public static int distanceToLine(Point start, Point end, Point point) {
		double x1 = start.getX();
		double x2 = end.getX();
		double x3 = point.getX();
		double y1 = start.getY();
		double y2 = end.getY();
		double y3 = point.getY();
		double d = start.distance(end);
		double u = (Math.abs(x3 - x1) * Math.abs(x2 - x1) + Math.abs(y3 - y1) * Math.abs(y2 - y1)) / (d * d);
		return (int) (new Point((int) (x1 + u * (x2 - x1)), (int) (y1 + u
				* (y2 - y1)))).distance(point);
	}
}
